
<?php


// echo implode(',', array('ee','ggg'));exit;
$aa='a:2:{s:5:"count";i:3;s:4:"date";s:10:"2016-10-27";}';
$data=unserialize($aa);
print_r($data);exit;
echo json_encode(array('err_msg'=>'每个用户只能创建并保存一个有效聊天室哦'));exit;
$array_data=array(array('timestamp'=>time()));
$array_data2=(object)array_values($array_data);



echo json_encode($array_data2);exit;

$time=date("Y-m-d H:i:s",strtotime("4 hours"));
// echo strtotime(date('Y-m-d'));  //今天凌晨

echo $time;exit;



//测试方法
$channels = array(
    array('id'=>1,'name'=>"衣服",'parId'=>0,'args'=>'clothes'),
    array('id'=>2,'name'=>"书籍",'parId'=>0,'args'=>'books'),
    array('id'=>3,'name'=>"T恤",'parId'=>1,'args'=>'func1,upload,clothes'),
    array('id'=>4,'name'=>"裤子",'parId'=>1,'args'=>'func2,upload,clothes'),
    array('id'=>5,'name'=>"鞋子",'parId'=>1,'args'=>'func3,upload,clothes'),
//    array('id'=>6,'name'=>"皮鞋",'parId'=>5),
//    array('id'=>7,'name'=>"运动鞋",'parId'=>5),
//    array('id'=>8,'name'=>"耐克",'parId'=>7),
//    array('id'=>9,'name'=>"耐克",'parId'=>3),
//    array('id'=>10,'name'=>"鸿星尔克",'parId'=>7),
    array('id'=>11,'name'=>"小说",'parId'=>2,'args'=>'func1,upload,books'),
//    array('id'=>12,'name'=>"科幻小说",'parId'=>11),
//    array('id'=>13,'name'=>"古典名著",'parId'=>11),
    array('id'=>14,'name'=>"文学",'parId'=>2,'args'=>'func1,upload,books'),
//    array('id'=>15,'name'=>"四书五经",'parId'=>14)
);

print_r(tree($channels,0,0,$html='--'));exit;

echo date("Y-m-d H:i:s",1474768035);exit;
// $a='a:3:{s:12:"access_token";s:34:"organization_application_not_found";s:11:"application";s:1:"0";s:10:"expires_in";d:1474106315673;}';
// print_r(unserialize($a));exit;
$a=explode(',', 'ee');
print_r($a);exit;
$type = pathinfo('aid_cover_22.avi'); 
$type = strtolower($type["extension"]); 
echo $type;exit;
// define('BasePath',str_replace('\\','/',dirname(__FILE__)));
include 'webApp/Common/Common/function.php';
$mime_type=getMimeType('./Uploads/association/aid_cover/aid_cover_22.avi');
echo $mime_type; exit;
// $imageType=getImagType('./Public/home/images/avataravatar_11.jpg');
// echo $imageType;
$a='N;';
if(unserialize($a)){
print_r('gg');
}
$b=null;
echo serialize($b);
exit;


//error_reporting(E_ALL);  //显示报错信息
//
//// sleep(10);     //等待10秒
//
//echo "test";
//ob_flush();       //存在输出缓存中的内容取出来，设置为等待输出状态
//flush();          //将等待输出缓存中内容，传给用户
//
////记录时间，以查看是否已经运行
//$aaa = fopen("test.txt","a+");
//fwrite($aaa, date("Y-m-d H:i:s")."\n");
//fclose($aaa);

//echo time();
//echo '<br>';
//echo strtotime('+7 day'); ;
//exit;
//define('PATH',str_replace('\\','/',dirname(__FILE__)));
//include PATH.'/ThinkYun/Library/Think/Verify.php';
//include dirname(__FILE__) . '\Verify.php';

//define('BasePath',str_replace('\\','/',dirname(__FILE__)));
//echo BasePath;exit;
//小用法
//if($files = '1,2,3'){
//    echo $files;
//}else{
//    echo '666';
//}
//exit;


//网站根目录
//$SiteUrl="http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
//$PHP_SELF=$_SERVER['PHP_SELF'];
//$url='http://'.$_SERVER['HTTP_HOST'].substr($PHP_SELF,0,strrpos($PHP_SELF,'/'));
//echo $url;exit;

//token加密测试
//$condition=array('pwd'=>re_md5(trim($_REQUEST['pwd'])));
//        if(!empty($_REQUEST['client'])){
//            $condition['mobile'] = $_REQUEST['mobile'];
//        }else{
//            $condition['email'] = $_REQUEST['email'];
//        }
//$condition['member_name'] = $_REQUEST['member_name'];
//$member_info = M('member')->where($condition)->find(); //判断用户时候存在
//if(!empty($member_info)) {
//    //重新登陆后以前的令牌失效
//    $condition = array();
//    $condition['member_id'] = $member_info['member_id'];
//    $condition['client_type'] = $_REQUEST['client'];
//    $this->tokenMod->delMbUserToken($condition);
//    //会员登录（重新生成token）
//    $token = $this->_get_token($member_info['member_id'], $member_info['member_name'], $_REQUEST['client']);
//    if($token) {
//        $this->myApiPrint('','',array('username' => $member_info['member_name'], 'key' => $token));
//    }else {
//        //令牌失效---code=-1
//        $this->myApiPrint('登录异常，请重新登录','-2','');
//    }
//} else {
//    $strToken = C('WKY_KEY').'|'.strtotime('+1 day'); //时间作为过期截止时间
//    $encode_string = myDes_encode($strToken,'');
//    if(strtotime('+1 day')>NOW_TIME){
//
//    }
//    $this->myApiPrint('账号密码异常，请重新登录','-1','');
//}

//计算连续签到天数,日期数组 按递减排序好
// $days = array('2016-06-07','2016-06-06','2016-06-05','2016-06-03','2016-06-02');
// echo continue_days($days).'<br/>'; //4


//输出验证码
// include('Verify.class.php');
// $config = array(
//     'fontSize'    => 14,
//     'length'      => 4,
//     'imageW'      => 100,
//     'imageH'    => 38,
//     'useNoise' => false,
//     //'useCurve' => false,
// );
// $verify = new Verify($config);
// $verify->entry(1);
// exit;


//下载图片
// define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
// $resource=BASE_ROOT_PATH.'/Public/home/images/avataravatar_11.jpg';
// downloads($resource);



/************************************************************自定义公共函数*************************************************************************************************************/
 //递归方法
function tree(&$list,$pid=0,$level=0,$html='--'){
    static $tree = array();
    foreach($list as $v){
        if($v['parId'] == $pid){
            $v['sort'] = $level;
             $v['html'] = str_repeat($html,$level);
            $tree[] = $v;
            tree($list,$v['id'],$level+1);
        } 
    }
    return $tree;
}

/**
 * 此方法由@Tonton 提供
 * http://my.oschina.net/u/918697
 * @date 2012-12-12 
 */
function genTree5($items) { 
    foreach ($items as $item) 
        $items[$item['parId']]['son'][$item['id']] = &$items[$item['id']]; 
    return isset($items[0]['son']) ? $items[0]['son'] : array(); 
} 
 
/**
 * 将数据格式化成树形结构
 * @author Xuefen.Tong
 * @param array $items
 * @return array 
 */
function genTree9($items) {
    $tree = array(); //格式化好的树
    foreach ($items as $item)
        if (isset($items[$item['parId']]))
            $items[$item['parId']]['son'][] = &$items[$item['id']];
        else
            $tree[] = &$items[$item['id']];
    return $tree;
}


//计算连续签到天数
function continue_days(array $date){
    $continue_day=1;
    foreach($date as $key=>$val){
        $base=($date[$key-1])?$date[$key-1]:$val;
        if($date[$key]==date("Y-m-d",strtotime("-1 day",strtotime($base)))){
            $continue_day++;
        }
    }
    return $continue_day;
}

/**
 * 屏蔽污秽词语
 * $content="dfdjfdf约炮jdkfjkdf约炮dfkdjf约炮kdj做爱吗fk顶顶顶顶djf"
 *
 */
function keywords_replace($content,$replacement="*"){
    $path=RUNTIME_PATH.'Exts/keyword.php';
    $data= include($path);
    foreach($data as $key=>$value){
        $content_length=mb_strlen($value,'UTF8');
        $replace_str="";
        for($i=0;$i<$content_length;$i++){
            $replace_str.=$replacement;
        }
        $content=str_replace($value,$replace_str,$content);//性能高
        $content=preg_replace('/'.$value.'/',$replace_str,$content,-1);//性能低
    }
    return $content;
}

//exit;
?>




<?php

/************************************************************无限菜单相关函数和获取权限菜单导航*************************************************************************************************************/

/*
 * 自定义入栈函数
 */
function pushStack(&$stack,$channel,$dep){
    array_push($stack, array('channel'=>$channel,'dep'=>$dep));
}
/*
 * 自定义出栈函数
 */
function popStack(&$stack){
    return array_pop($stack);
}

/*
 * 使用非递归，即使用栈的方式实现栏目的无限极分类查询
 */
function get_tree_array($data=array()){
    $stack = array(); //定义一个空栈
    $html = array();  //用来保存各个栏目之间的关系以及该栏目的深度
    //首先将顶级栏目压入栈中
    foreach($data as $key=>$val){
        if($val['parId'] == 0)
            pushStack($stack,$val,0);
    }
    // 将栈中的元素出栈，查找其子栏目
    do{
        $par = popStack($stack); //将栈顶元素出栈
        //查找以此栏目为父级栏目的id，将这些栏目入栈
        for($i=0;$i<count($data);$i++){
            if($data[$i]['parId'] == $par['channel']['id']){
                pushStack($stack,$data[$i],$par['dep']+1);
            }
        }
        //将出栈的栏目以及该栏目的深度保存到数组中
        $html[] = array('parId'=>$par['channel']['parId'],'id'=>$par['channel']['id'],'name'=>$par['channel']['name'],'dep'=>$par['dep'],'args'=>$par['channel']['args']);
    }while(count($stack)>0);
    return $html;
}

/*
 * 获取权限菜单导航
 */
function getPurviewMenuNav($data=array()){
    $all_array=array();  //所有菜单二维数组，以id为索引 array(1=>array(id=>1,),2=>array(id=>2,),3=>array(id=>3,))
    $topMenu=array();  //一级菜单
    $leftMenu=array(); //二级菜单
    $leftMenu1=array();//顶部一级菜单（shopnc格式化）
    $leftMenu2=array();//左边二级菜单（shopnc格式化）
    $menu=array();   //合并顶部和左边菜单（shopnc格式化）
    $dataSources=get_tree_array($data);
    foreach($dataSources as $key=>$value){
        if($value['dep']==0){
//        $level1[$value['parId']][]=$value;
            $topMenu['top'][]=$value;
        }elseif($value['dep']==1){
//        $level2[$value['parId']][]=$value;
            $leftMenu['left'][]=$value;
        }elseif($value['dep']==2){
//        $level3[$value['parId']][]=$value;
        }
        $all_array[$value["id"]]=$value; //取得所有菜单二维数组，以id为索引（方便后面获取任何一个菜单的信息）
    }
//重组顶部菜单数组
    foreach($topMenu['top'] as $key=>$value){
        $value['text']=$all_array[$value['id']]['name'];
        $value['args']=$all_array[$value['id']]['args'];
        $leftMenu1['top'][$value['id']]['text']=$value['text'];
        $leftMenu1['top'][$value['id']]['args']=$value['args'];
    }
//重组左边菜单数组
    foreach($leftMenu['left'] as $key=>$value){
        $value['text']=$all_array[$value['parId']]['name'];
        $value['args']=$all_array[$value['parId']]['args'];
        $value['args_chilid']=$all_array[$value['id']]['args'];
        $temp=$value;
        $temp['args']=$temp['args_chilid'];
        $leftMenu2['left'][$temp['parId']]['nav']=$value['args'];
        $leftMenu2['left'][$temp['parId']]['text']=$temp['text'];
        unset($temp['args_chilid']);
        $temp['text']=$temp['name'];
        unset($temp['name']);
        $leftMenu2['left'][$temp['parId']]['list'][]=$temp;

    }
//合并顶部和左边菜单数组
    $menu['top']=$leftMenu1['top'];
    $menu['left']=$leftMenu2['left'];
    return $menu;
}

//测试方法
$channels = array(
    array('id'=>1,'name'=>"衣服",'parId'=>0,'args'=>'clothes'),
    array('id'=>2,'name'=>"书籍",'parId'=>0,'args'=>'books'),
    array('id'=>3,'name'=>"T恤",'parId'=>1,'args'=>'func1,upload,clothes'),
    array('id'=>4,'name'=>"裤子",'parId'=>1,'args'=>'func2,upload,clothes'),
    array('id'=>5,'name'=>"鞋子",'parId'=>1,'args'=>'func3,upload,clothes'),
//    array('id'=>6,'name'=>"皮鞋",'parId'=>5),
//    array('id'=>7,'name'=>"运动鞋",'parId'=>5),
//    array('id'=>8,'name'=>"耐克",'parId'=>7),
//    array('id'=>9,'name'=>"耐克",'parId'=>3),
//    array('id'=>10,'name'=>"鸿星尔克",'parId'=>7),
    array('id'=>11,'name'=>"小说",'parId'=>2,'args'=>'func1,upload,books'),
//    array('id'=>12,'name'=>"科幻小说",'parId'=>11),
//    array('id'=>13,'name'=>"古典名著",'parId'=>11),
    array('id'=>14,'name'=>"文学",'parId'=>2,'args'=>'func1,upload,books'),
//    array('id'=>15,'name'=>"四书五经",'parId'=>14)
);
$menu=getPurviewMenuNav($channels);

//将菜单写入文件缓存
//$content = var_export($menu, TRUE);
//$path=RUNTIME_PATH.'Exts/mebu.php';
//file_put_contents($path, "<?php "."\n"."return ".$content.";");
//读取缓存文件
//    $path=RUNTIME_PATH.'Exts/keyword.php';
//    $data= include($path);

print_r($menu);
exit;


/*
 * --------------------------------------------------------------------------------------------------------------------------
 *php常用代码:switch
 *
 *     switch (ACTION_NAME)
        {
            case 'index':
                $check_fields=$this->index_check_fields;
                break;
            case 2:
                $check_fields=$this->index_check_fields;
                break;
            case 3:
                $check_fields=$this->index_check_fields;
                break;
            default:
                break;
        }
 *
 *
 *
 * * --------------------------------------------------------------------------------------------------------------------------
*/

?>


